package com.syyo.gulimall.order.listener;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.rabbitmq.client.Channel;
import com.syyo.common.to.mq.SeckillOrderTo;
import com.syyo.gulimall.order.config.pay.AlipayTemplate;
import com.syyo.gulimall.order.domain.entity.OrderEntity;
import com.syyo.gulimall.order.domain.vo.PayAsyncVo;
import com.syyo.gulimall.order.service.OrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: wangzhong
 * @Date: 2020/7/30 10:54
 * @Description:
 */
@RestController
public class OrderSeckillListener {

    @Autowired
    OrderService orderService;

    /**
     *   order.seckill.order.queue
     */
    @RabbitListener(queues = "order.seckill.order.queue")
    public void listen(SeckillOrderTo to,
                       Message msg,
                       Channel channel) throws IOException {
        System.out.println("===============创建秒杀单详细信息:"+to.getOrderSn()+"===============");
        try {
            // 当消息是第二次及以后派发的就为true
            orderService.createSeckillOrder(to);
            channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            // 发送请求失败,重新回队
            channel.basicReject(msg.getMessageProperties().getDeliveryTag(), true);

        }


    }
}
